package cn.xiaopengstack.infrastructure.persistent.dao;

import cn.xiaopengstack.infrastructure.persistent.po.GroupBuyOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* @author jiangyangang
* @description 针对表【group_buy_order(拼团订单表)】的数据库操作Mapper
* @createDate 2025-10-16 17:42:38
* @Entity cn.xiaopengstack.infrastructure.persistent.po.GroupBuyOrder
*/
@Mapper
public interface IGroupBuyOrderDao {


    int insertSelective(GroupBuyOrder record);

    GroupBuyOrder selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(GroupBuyOrder record);

    /**
     * 查询拼团订单
     * @param teamId
     * @return
     */
    GroupBuyOrder queryGroupBuyOrderByTeamId(@Param("teamId") String teamId);

    /**
     * 更新锁定次数
     * @param teamId
     * @return
     */
    int updateAddLockCount(@Param("teamId") String teamId);

    /**
     * 更新完成数量
     * @param teamId
     * @return
     */
    int updateCountBySettlement(@Param("teamId") String teamId);

    /**
     * 更新拼团订单状态
     * @param teamId
     * @return
     */
    int updateCompleteStatus(@Param("teamId") String teamId);

    /**
     * 查询拼团中的订单
     * @param activityId
     * @param goodsId
     * @param source
     * @param channel
     * @param count
     * @return
     */
    List<GroupBuyOrder> queryInProgressOrder(@Param("activityId") Long activityId,
                                             @Param("goodsId") String goodsId,
                                             @Param("source") String source,
                                             @Param("channel") String channel,
                                             @Param("count") Integer count)
                                       ;


    /**
     * 查询所有的拼团数量
     * @param activityId
     * @param goodsId
     * @return
     */
    List<GroupBuyOrder> queryAllGroupBuyOrders(@Param("activityId") Long activityId, @Param("goodsId") String goodsId);

    /**
     * 更新退款后完成订单的次数
     * @param teamId
     * @return
     */
    int updateCountByRefund(@Param("teamId") String teamId);

    /**
     * 更新退款后锁定订单的次数
     * @param teamId
     * @return
     */
    int updateLockCountByRefund(@Param("teamId") String teamId);

    /**
     * 退款场景下，修改组团的状态和回退完成的次数
     * @param teamId
     * @param status
     * @return
     */
    int updateCompleteCountAndStatusByRefund(@Param("teamId") String teamId, @Param("status") int status);

    /**
     * 退掉整笔单
     * @param teamId
     * @return
     */
    int updateRefundAllTeam(@Param("teamId") String teamId);

    /**
     * 查询剩余拼团人数数据
     * @param teamId
     * @return
     */
    GroupBuyOrder queryRemainNumberByTeamId(@Param("teamId") String teamId);
}
